import java.util.HashMap;
import java.util.Map;

public class Test01 {
    public static int tongji(String str, Character ch) {
        HashMap<Character, Integer> map = new HashMap<>();
        char[] charArray = str.toCharArray();
        for (Character c : charArray) {
            // 先检查map中是否已经存在该字符
            if (map.get(c) == null) {
                map.put(c, 1);
            } else {
                map.put(c, map.get(c) + 1);
            }
        }
        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
            if (entry.getKey() == ch) {
                return entry.getValue();
            }
        }
        return 0; // 如果字符不存在于map中，返回0
    }

    public static void main(String[] args) {
        String str = "hello world";
        Character ch = 'l';
        int count = tongji(str, ch);
        System.out.println("字符 '" + ch + "' 出现的次数: " + count);
    }
}
